<?php

namespace Admin\Controller;

/**
 * 账目控制器
 */
class AccountController extends AdminController
{
	/**
	 * 账目流水
	 * @param  string $uid [用户id]
	 */
	public function index($uid='',$action='',$record='',$nickname=''){
		//流水列表
		if (is_numeric($uid)) {
			$where['uid'] = $uid;
		}
		if (is_numeric($action)) {
			$where['action'] = $action;
		}
		if (is_numeric($record)) {
			$where['record'] = $record;
		} else {
			$record = $_GET['record'] = 0;
		}
		$where['action'] = array('in',"0,1,2");
		// dump($where);
		$data = $this -> lists('Account',$where,'create_time desc');
		// echo M() -> _sql();
		$admin = D('Home/UserMember') -> showUser(0);
		foreach ($data as &$v) {
			$res = D('Home/UserMember') -> showUser($v['uid']);
			$v['nickname'] = $res['nickname'];					/* yxf 20171108 金额有几位小数就显示几位  S*/						$v['change'] = floatval($v['change']);
		}				unset($v);		$admin['account'] = floatval($admin['account']);				/* yxf 20171108 金额有几位小数就显示几位  E*/		
		$this -> assign('account', $admin['account']);	
		$this -> assign('data', $data);
		$this -> display();
	}

	/**
	 * 修改流水条目状态：未记录，已记录
	 * @return [type] [description]
	 */
	public function edit(){
		if (IS_AJAX) {
			$id = I('post.id');
			$val = I('post.val');
			$flag = I('post.flag');
			if (D('Home/Account') -> edit($id, $val, $flag)) {
				$this -> ajaxReturn('操作成功');
			} else {
				// echo M() -> _sql();die;
				$this -> ajaxReturn('出错了');
			}
		}
	}
	/*
	 * 商户放款操作
	 */
	function operate()
	{
		$config=array
		(
			'mchid'=>'1415819602','appid'=>'wx24af86636d874b65','key'=>'x123s55654s789z84x21s56x5445x222',
		);
		//$openid="ovcHkw8mB8z7kdC7MbxtAEKkmHZU";//
		$openid=  "ovcHkw4k5AfxGAULjtglyhIuOUtA";//
		$re_user_name="孙盼坤";
		$amount=1;//元
		extract($config);
		Vendor('Weixinpay.QYPayWxpayService');
		$service=new \QYPayWxpayService($mchid, $appid, $key);
		$data=$service->createPayPackage($openid,$re_user_name,$amount);
		echo $data;
	}

}
